var temp = {
  dictionariesId:null,
  dictionariesName: null
}

$(function () {
  //抽取js变量
  var dictionaries_datagrid = $("#dictionaries_datagrid");
  var dictionaries_dialog = $("#dictionaries_dialog");
  var dictionaries_form = $("#dictionaries_form");


  dictionaries_datagrid.datagrid({
    url:'/dictionaries/query.do',
    fitColumns:true,
    fit:true,//自动填充
    toolbar:'#dictionaries_toolbar',
    pagination:true, //在DataGrid控件底部显示分页工具栏
    rownumbers:true, //显示一个行号列。
    singleSelect:true,//只允许选择一行
    striped:true, //显示斑马线效果
    columns:[[
      {field:'sn',title:'目录编号',width:80},
      {field:'name',title:'目录名称',width:80},
      {field:'info',title:'目录简介',width:80},
    ]],
    //
    onClickRow:function (index, row) {
      $('#details_datagrid').datagrid('load',{
        sn: row.sn
      });
    }

  });


  var methodObj = {
    add:function () {
      //打开弹出框
      dictionaries_dialog.dialog('open');
      //设置标题
      dictionaries_dialog.dialog('setTitle','新增菜单');

    },

    save:function () {
      //提交表单
      dictionaries_form.form('submit',{
        url:'/dictionaries/saveOrUpdate.do',
        onSubmit:function (param) {
          //手动调用验证表单的方法
          return dictionaries_form.form('validate');
        },

        success:function (data) {
          data = $.parseJSON(data);
          if(data.success){
            //提示用户操作结果
            $.messager.alert('温馨提示','保存成功!','info',function () {
              //关闭弹出框
              methodObj.cancel();
              //让datagrid重新重新菜单数据
              dictionaries_datagrid.datagrid('reload');
              //同时刷新明细菜单数据
              $("#dictionariesItem_datagrid").datagrid('reload');
            })

          }else{
            $.messager.alert('温馨提示',data.msg,'error')
          }
        }
      })
    },
    cancel:function () {
      dictionaries_dialog.dialog('close');
    },
    reload:function () {
      dictionaries_datagrid.datagrid('load');
    }
  }


  $("a[data-cmd]").click(function () {
    var methodName = $(this).data("cmd");
    methodObj[methodName]();
  })


  dictionaries_dialog.dialog({
    width:300,
    height:385,
    buttons:'#form_btns',
    closed:true,
    onClose:function () {
      //清空表单
      dictionaries_form.form('clear');
    }
  })
})